package ooday03;

public class RefArrayDemo {
    public static void main(String[] args) {
        //创建一个Dog类型数组dogs，包含三个元素，每个元素都是Dog类型，默认值是null
        Dog []dogs=new Dog[3];
        dogs[0]=new Dog("小黑",2,"黑");
        dogs[1]=new Dog("小白",3,"白");
        dogs[2]=new Dog("小绿",3,"绿");
        System.out.println(dogs[0].name);
        dogs[1].eat();
        for(int i=0;i<dogs.length;i++){
            System.out.println(dogs[i].name);
            dogs[i].lookHome();
        };
        //创建一个Chick型数组chiks，包含三个元素，每个元素都是Chick类型，默认值是null
        Chick[]chicks=new Chick[3];
        chicks[0]=new Chick("小黄",2,"黄");
        chicks[1]=new Chick("小白",1,"白");
        chicks[2]=new Chick("小花",1,"花");
        System.out.println(chicks[1].age);
        chicks[2].eat();
        for(int i=0;i<chicks.length;i++){
            System.out.println(chicks[i].age);
            chicks[i].layEgg();
        }
        //创建一个Fish类型数组fish，包含两个元素，每个元素都是Fish类型，默认值是null
        Fish[]fish=new Fish[2];
        fish[0]=new Fish("小金",1,"金");
        fish[1]=new Fish("小红",2,"红");
        System.out.println(fish[0].color);
        fish[1].eat();
        for(int i=0;i<fish.length;i++){
            System.out.println(fish[i].color);
            fish[i].swim();
        }
    }
}
